<script setup>
import { reactive, computed } from 'vue'

const author = reactive({
  name: 'John Doe',
  books: [
    'Vue 2 - Advanced Guide',
    'Vue 3 - Basic Guide',
    'Vue 4 - The Mystery'
  ]
})

// 一个计算属性 ref
const publishedBooksMessage = computed(() => {
  return author.books.length > 0 ? 'Yes' : 'No'
})

function calculateBooksMessage() {
  return author.books.length > 0 ? 'Yes' : 'No'
}

function cleanBooks() {
    author.books=[];
}
</script>

<template>
    <p>{{ author }}</p>
    <p>模板中的表达式 Has published books:</p>
    <span>{{ author.books.length > 0 ? 'Yes' : 'No' }}</span>
    <p>计算属性 Has published books:</p>
    <span>{{ publishedBooksMessage }}</span>
    <p>函数 Has published books:</p>
    <span>{{ calculateBooksMessage() }}</span>
    <p>
        <button @click="cleanBooks">清空</button>
    </p>
</template>